"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const configTool_1 = __importDefault(require("../../com/configTool"));
const LogTool_1 = __importDefault(require("../../com/LogTool/LogTool"));
function logHandler() {
    return async (ctx, next) => {
        await configTool_1.default.init();
        const logObj = {
            ip: ctx.request.ip,
            method: ctx.request.method,
            start: new Date().toLocaleString(),
            passSecond: 0,
            url: decodeURI(ctx.request.url)
        };
        await next();
        if (logObj.url === '/'
            || logObj.url.startsWith('/MapResources/')
            || logObj.url.startsWith('/Resources/')
            || logObj.url.startsWith('/Web')
            || logObj.url.startsWith('/favicon.ico')) {
            return;
        }
        logObj.passSecond = (new Date().getTime() - new Date(logObj.start).getTime()) / 1000;
        const logger = await LogTool_1.default.getLogger();
        logger.info(`http`, { message: JSON.stringify(logObj) });
    };
}
exports.default = logHandler;
